#-*-encoding=utf-8-*-
steps = [
    FlowStep(
        name=u'init',
        title=u'Submit',
        fields=[u'ipde', u'categories', u'command', u'manager', u'project_name'],
        trigger=ur"""""",
        responsibles=u'[request.principal.id]',
    actions=[
        FlowStepAction(
            name=u'提交',
            title=u'Submit',
            nextsteps=[u'review'],
            trigger=ur"""##Gen SZN_Order
sheet['title'] = "增加项目-%s" % sheet['project_name']
category = sheet['categories']
szn_info = ITinyTable(flowsettings['categories']).queryOneRow(cat_name = category)
sheet['szn_order'] = "%d-%d" % (szn_info['cat_no'], szn_info['cat_start_no'])
szn_info['cat_start_no'] = szn_info['cat_start_no'] + 1

##Send Notification
to_ids = []

#Send notify
general_manager = IFieldStorage(parentcontainer)['general_manager']
to_ids.append(general_manager[0])

url = absoluteURL(sheet, request)
body = "New project request,for details please visit:%s" % (url)
notifier_message.send('New project request', body, to_ids)
""",
            finish_condition=u'',
            condition=u'True'
)
])
,

    FlowStep(
        name=u'review',
        title=u'Review',
        fields=[],
        trigger=ur"""""",
        responsibles=u'[request.principal.id]',
    actions=[
        FlowStepAction(
            name=u'审核通过',
            title=u'Approve',
            nextsteps=[],
            trigger=ur"""#Get sheet data
project_name = sheet['project_name']
ipde = sheet['ipde']
szn_order = sheet['szn_order']
categories = sheet['categories']
command = sheet['command']
prj_data = {'project_name':project_name, 'ipde':ipde,
            'szn_order':szn_order, 'categories':categories,
            'command':command}

project_tb = parentcontainer['projects']
project_tb.addRow(prj_data)

##Send Notification
to_ids = []

#Send to creator
creators = IDublinCore(sheet).creators
for uid in creators:
    to_ids.append(uid)

manager = sheet['manager'][0]
if manager:
    to_ids.append(manager)

url = absoluteURL(sheet, request)
body = "Project <%s @ %s> is approved,for details please visit:%s" % (project_name, categories, url)
notifier_message.send('Project request approved', body, to_ids)
""",
            finish_condition=u'',
            condition=u'True'
),

        FlowStepAction(
            name=u'拒绝',
            title=u'Refuse',
            nextsteps=[],
            trigger=ur"""#Get sheet data
project_name = sheet['project_name']
categories = sheet['categories']

##Send Notification
to_ids = []

#Send to creator
creators = IDublinCore(sheet).creators
for uid in creators:
    to_ids.append(uid)

manager = sheet['manager'][0]
if manager:
    to_ids.append(manager)

url = absoluteURL(sheet, request)
body = "Project <%s @ %s> is rejected, for details please visit:%s" % (project_name, categories, url)
notifier_message.send('Project request rejected', body, to_ids)
""",
            finish_condition=u'',
            condition=u'True'
)
])
]
